'use strict';

/**
 * @ngdoc directive
 * @name App.directive:pagerLoading
 * @description
 * # pagerLoading
 */
angular.module('App')
  .directive('pagerLoading', ['$location', '$anchorScroll', function ($location, $anchorScroll) {
    return {
      template: '<div class="pager-loading text-white"><i class="fa fa-spinner fa-spin fa-5x m-b"></i><p class="text-base">数据加载中...</p></div>',
      restrict: 'AE',
      replace: true,
      link: function postLink(scope, element, attrs) {
        scope.$on('$stateChangeStart', function() {
          NProgress.start();
          element.removeClass('hide').addClass('show');
        });

        scope.$on('$stateChangeSuccess', function() {
          NProgress.done();
          $location.hash('top');
          $anchorScroll();
          element.addClass('hide').removeClass('show');
        });
      }
    };
  }]);
